package com.company.bilibili;

import java.util.Scanner;
import java.util.Stack;

// 括号闭合
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        System.out.println(IsValidExp(str));

    }

    public static boolean IsValidExp(String s) {
        // write code here
        if (s == null || s == "" || s.length() == 0) {
            return true;
        }
        Stack<Character> stack = new Stack<>();
        int len = s.length();
        for (int i = 0; i < len; i++) {
            char c = s.charAt(i);
            if (c == '(' || c == '{' || c == '[') {
                stack.push(c);
            }

            if (c == ']') {
                if (stack.isEmpty() || stack.peek() != '[') {
                    return false;
                }
                if (stack.peek() == '[') {
                    stack.pop();
                }
            }
            if (c == '}') {
                if (stack.isEmpty() || stack.peek() != '{') {
                    return false;
                }
                if (stack.peek() == '{') {
                    stack.pop();
                }
            }
            if (c == ')') {
                if (stack.isEmpty() || stack.peek() != '(') {
                    return false;
                }
                if (stack.peek() == '(') {
                    stack.pop();
                }
            }
        }

        return stack.isEmpty();

    }
}
